﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Net;
using System.IO;

namespace WPF_DbCenter.SqlCE.UI
{
    /// <summary>
    /// Interaction logic for DownloadSdf.xaml
    /// </summary>
    public partial class DownloadSdf : Window
    {
        public DownloadSdf()
        {
            InitializeComponent();

        }

        private void butDownload_Click(object sender, RoutedEventArgs e)
        {
            string uri=textBox1.Text;
            string file=textBox2.Text;
            if (string.IsNullOrEmpty(uri))
            {
                MessageBox.Show("Please input the URI");
                return;
            }

            if(File.Exists(file))
            {
                if(MessageBox.Show("The file has existed , do you want to override it ? ","Warning",MessageBoxButton.YesNo,
                    MessageBoxImage.Warning,MessageBoxResult.No)!=MessageBoxResult.Yes)
                {
                    return;
                }
            }

            WebClient wb = new WebClient();
            wb.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(wb_DownloadFileCompleted);
            wb.DownloadFileAsync(new Uri(uri), file);
        }

        void wb_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            MessageBox.Show("Complete");
        }
    }
}
